import BaseHttp from "./BaseHttp"

export default class News extends BaseHttp {
    constructor() {
        super()//在构造函数中使用父类的构造函数
    }

    //获取Top3News
    async GetTop3News() {
        return (await this.get('WebSpecialNews/HomePageTop3News')).data;
    }

    //获取首页轮播图News
    async GetIndexPageSlider6() {
        return (await this.get('WebSpecialNews/HomePageSlider6News')).data;
    }

    //获取Weight排名前10News
    async GetTop10News() {
        return (await this.get('News/NewsByCount/10')).data;//查到所有的News，取前10条，实际上就该在后台封装好api，只返回前10个News
    }

    //获取前6个NewsCategory下的6个新闻,用于Carousel
    async GetCarousel6NewsByNewsCategoryId(newsCategoryId) {
        let targetUrl = 'WebSpecialNews/CategorySlider6News/' + newsCategoryId;
        return (await this.get(targetUrl)).data;
    }

    //根据NewsCategoryId获取新闻,
    async GetNewsByNewsCategoryId(newsCategoryId) {
        let targetUrl = 'News/NewsByCategory/' + newsCategoryId;
        return (await this.get(targetUrl)).data;
    }


    //根据NewsCategoryId获取前count个新闻,
    async GetTop6NewsByNewsCategoryId(newsCategoryId, count) {
        let targetUrl = 'News/NewsByCategoryAndCount/' + newsCategoryId + '?count=' + count;
        return (await this.get(targetUrl)).data;
    }

    //根据Id获取News
    async GetNewsById(id) {
        return (await this.get('News/' + id)).data;
    }

    //根据AppUserId获取新闻,InShow
    async GetNewsByAppUserId(appUserId) {
        let targetUrl = 'News/NewsByAuthorId/' + appUserId;
        return (await this.get(targetUrl)).data;
    }


    //根据AppUserId获取前count个新闻,InShow
    async GetTopCountNewsByAppUserId(appUserId, count) {
        const response = await this.GetNewsByAppUserId(appUserId)
        return response.data.slice(0, count);
    }

    //根据AppUserId获取新闻,ToAudit
    async GetNewsToAuditByAppUserId(appUserId) {
        let targetUrl = 'News/NewsByAuthorIdToAudit/' + appUserId;
        return (await this.get(targetUrl)).data;
    }

    //根据AppUserId获取前count个新闻,ToAudit
    async GetTopNewsToAuditByAppUserId(appUserId, count) {
        const response = await this.GetNewsByAppUserId(appUserId)
        return response.data.slice(0, count);
    }


    //根据NewsCategoryId修改新闻
    async UpdateNews(news, token) {
        let targetUrl = 'News/UpdateNewsInLogin';
        const targetToken = "Bearer " + token
        const response = await this.putWithParams(targetUrl, news, {
            Authorization: targetToken
        })
        return response.data;
    }

    //根据NewsId删除新闻，此处调用方法只允许删除AppUser名下的新闻
    async DeleteNews(id, token) {
        let targetUrl = 'News/DeleteNewsInLogin/' + id;
        const targetToken = "Bearer " + token
        const response = await this.deleteWithParams(targetUrl, {
            Authorization: targetToken
        })
        return response.data;
    }


    //当前登陆用户创建新闻
    async CreateNewsInLogin(data, token) {
        let targetUrl = 'News/CreateNewsInLogin';
        const targetToken = "Bearer " + token
        const response = await this.postWithParams(targetUrl, data, {
            Authorization: targetToken
        })
        return response.data;
    }






}